package cn.zhb.backend.core.entity;

import cn.zhb.backend.handler.CommaSeparatedLongListJPAHandler;
import cn.zhb.backend.handler.CommaSeparatedLongListMpHandler;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/***
 *@Description
 *@Author ZHB
 *@Create 2025/7/3 下午8:29
 **/
@Data
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@Entity
@Table(name = "bus_user_question_record")
@TableName("bus_user_question_record")
@ApiModel("用户学习记录")
public class UserQuestionRecord extends BaseEntity {

    @ApiModelProperty("关联用户")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id", nullable = false)
    @TableField(exist = false)
    private User user;

    @ApiModelProperty("关联用户ID")
    @Column(name = "user_id", insertable = false, updatable = false)
    @TableField("user_id")
    private Long userId;

    @ApiModelProperty("关联分类")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "category_id", nullable = false)
    @TableField(exist = false)
    private Category category;

    @ApiModelProperty("关联分类ID")
    @Column(name = "category_id", insertable = false, updatable = false)
    @TableField("category_id")
    private Long categoryId;

    // 使用JSON类型存储已完成题目ID列表
    @ApiModelProperty("关联分类下已完成题目ID")
    @Convert(converter = CommaSeparatedLongListJPAHandler.class)
    @Column(name = "completedQuestionIds")
    @TableField(value = "completedQuestionIds", typeHandler = CommaSeparatedLongListMpHandler.class)
    private List<Long> completedQuestionIds = new ArrayList<>();

}
